<template>
    <view>
        <view class="cu-list menu sm-border card-menu margin-top">
            <view class="cu-item" @tap="showAll()">
                <view class="action">
                    <text class="cuIcon-title text-orange"></text>
                    {{params.from_section}}-{{params.to_section}}节无课人员
                </view>
                <view :class="'cuIcon-'+(showTotal?'unfold':'right')"></view>
            </view>
            <view class="cu-item" v-if="showTotal && totalData.length === 0">
                <view class="content">
                    <view class="text-grey flex justify-center">
                        <span>全都有课哦</span>
                    </view>
                </view>
            </view>
            <view class="cu-item" v-for="(item,index) in totalData" v-if="showTotal">
                <img class="margin-left cu-avatar round" :src="ApiUrl+item.avatar"/>
                <view class="content">
                    <view class="margin-left text-grey">{{item.sid}}-{{ item.name }}</view>
                </view>
            </view>

        </view>

        <view v-for="i in sections">
            <view class="cu-list menu sm-border card-menu margin-top">
                <view @tap="showSingle(i-params.from_section)" class="cu-item">
                    <view class="action">
                        <text class="cuIcon-title text-blue"></text>
                        第{{ i }}节无课人员
                    </view>
                    <view :class="'cuIcon-'+(show[i-params.from_section]?'unfold':'right')"></view>
                </view>
                <view class="cu-item" v-if="show[i-params.from_section] &&  data[i+''].length === 0">
                    <view class="content">
                        <view class="text-grey flex justify-center">
                            <span>全都有课哦</span>
                        </view>
                    </view>
                </view>
                <view class="cu-item" v-for="(item,index) in data[i+'']" v-if="show[i-params.from_section]">
                    <img class="margin-left cu-avatar round" :src="ApiUrl+item.avatar"/>
                    <view class="content">
                        <view class="margin-left text-grey">{{item.sid}}-{{ item.name }}</view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>

const app = getApp();

export default {
    data() {
        return {
            totalData: [],
            data: [],
            showTotal: false,
            show: [],
            params: {
                from_section:-1,
                to_section:-1
            },
            ApiUrl: '',
            sections:[]
        }
    },
    onLoad(e) {

        this.ApiUrl = app.globalData.ApiUrl

        e.SafeCode = uni.getStorageSync('SafeCode');
        this.params = e;

        let tempShow = [];
        let tempSection = [];
        for (let i = parseInt(e.from_section); i <= parseInt(e.to_section); i++) {
            tempShow.push(false);
            tempSection.push(i+'');
        }
        this.show = tempShow;
        this.sections = tempSection;
        console.log(this.sections);
        console.log(e);
        this.getNoClassUser()

    },
    onBackPress(e) {
        uni.reLaunch({
            url: '../../pages/association/timetable/search?id=' + this.id
        });
    },
    methods: {
        showAll() {
            this.showTotal = !this.showTotal;
        },
        showSingle(e) {
            let tempShow = []
            for (let i = 0; i < this.params.to_section - this.params.from_section + 1; i++) {
                if (i === e ) {
                    tempShow.push(!this.show[i]);
                } else {
                    tempShow.push(this.show[i]);
                }
            }
            this.show = tempShow;
        },
        getNoClassUser() {

            let that = this;
            this.$myFunction.getData(
                app.globalData.ApiUrl + 'api/Android/getNoClassUserList', this.params
            ).then(this.process)

        },
        process(res) {

            console.log(res);

            if (res.code != 1) {
                uni.showModal({
                    title: res.msg,
                    icon: "none"
                })
            } else {
                this.totalData = res.data.total;
                let tempData = {}
                for (let i = this.params.from_section; i <= this.params.to_section; i++) {
                    tempData[i + ''] = res.data['' + i];
                }
                this.data = tempData;

                console.log(this.data);
            }
        }
    }
}


</script>


